import {Component, OnInit} from '@angular/core';
import {ApisService} from '../../apis.service';
import {ActivatedRoute} from '@angular/router';
import {LocalStorageService} from '../../local-storage.service';

@Component({selector: 'app-view', templateUrl: './view.component.html', styleUrls: ['./view.component.css']})
export class ViewComponent implements OnInit {
  private lStorage : LocalStorageService = new LocalStorageService();
  constructor(private route : ActivatedRoute, private apiService : ApisService) {}
  goodsinfo:any = {};
  ngOnInit() {
    this
      .route
      .params
      .subscribe(x => {
        var info = this
          .lStorage
          .getObject("info_" + x.id);
        if (info) {
          this.goodsinfo = info;
        } else {
          this
            .apiService
            .iteminfo({NumIids: x.id})
            .then(result => {
              var data = result.goods_info.tbk_item_info_get_response;
              if (data && data.results && data.results.n_tbk_item.length > 0) {
                this.goodsinfo = data.results.n_tbk_item[0];
              }
            });
        }
      });
  }

}
